package utils.adapter;

import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.android.volley.toolbox.NetworkImageView;
import com.lanou.horo.myapplication.R;

import java.util.List;

import entity.LiveFmEntity;
import volley.VolleySingleton;

/**
 * 直播适配器
 * Created by dllo on 15/11/20.
 */
public class LiveFmAdpter extends RecyclerView.Adapter<LiveFmAdpter.RecyerAdpter> {
    private List<LiveFmEntity.ResultEntity> live;
    public  void add(List<LiveFmEntity.ResultEntity> live){
        this.live = live;
        notifyDataSetChanged();
    }


    @Override
    public RecyerAdpter onCreateViewHolder(ViewGroup parent, int viewType) {
        LayoutInflater inflater = LayoutInflater.from(parent.getContext());
        View view = inflater.inflate(R.layout.live_pagr_item,null);

        return new RecyerAdpter(view);


    }

    @Override
    public void onBindViewHolder(RecyerAdpter holder, int position) {
        LiveFmEntity.ResultEntity fm = live.get(position);
        if (live!= null && live.size() >0){
            double firstPlaysCounts = ((double)live.get(position).getRadioPlayCount() / 10000);
            String firstPC = String.format("%1$.2f",firstPlaysCounts);
            holder.contentTvOne.setText(firstPC+"万次");
            holder.fm_now_one.setText(fm.getProgramName());
            holder.fm_name_one.setText(fm.getRname());
            VolleySingleton.getInstance().getBitmap(fm.getRadioCoverSmall(),
                    holder.live_pOne_IV);
        }

    }

    @Override
    public int getItemCount() {
        return live!=null && live.size()>0?live.size():0;
    }

    class RecyerAdpter extends RecyclerView.ViewHolder {
        private TextView fm_name_one,fm_now_one,contentTvOne;
        private NetworkImageView live_pOne_IV;

        public RecyerAdpter(View itemView) {
            super(itemView);
            fm_name_one= (TextView) itemView.findViewById(R.id.fm_name_one);

            fm_now_one = (TextView) itemView.findViewById(R.id.fm_now_one);
            contentTvOne= (TextView) itemView.findViewById(R.id.contentTvOne);
            live_pOne_IV = (NetworkImageView) itemView.findViewById(R.id.live_pOne_IV);
        }
    }

}
